//
//  DDChangeView.m
//  DingDongZP
//
//  Created by 杨政涛 on 16/8/3.
//  Copyright © 2016年 51ledian.com. All rights reserved.
//

#import "DDChangeView.h"

@implementation DDChangeView

- (id)initWithCreatPopViewframe:(CGRect)frame andShowText:(NSString *)showText
{
    self = [super initWithFrame:frame];
    if (self) {
        self.windowShadowView = [[UIView alloc] init];
        self.windowShadowView.userInteractionEnabled = YES;
        self.windowShadowView.frame = frame;
        self.windowShadowView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
        
        AppDelegate *app=(AppDelegate *)[UIApplication sharedApplication].delegate;
        [app.window.rootViewController.view addSubview:self.windowShadowView];
        
        UIImageView *changeLogoImage = [[UIImageView alloc]init];
        changeLogoImage.image = [UIImage imageNamed:@"缓冲动画"];
        [self.windowShadowView addSubview:changeLogoImage];
        
        [changeLogoImage mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.width.equalTo(@(40));
            make.height.equalTo(@(40));
            make.centerX.equalTo(self.windowShadowView);
            
            if ([showText isEqualToString:@"正在切换至牛人版首页"]) {
                
                make.centerY.equalTo(self.windowShadowView).offset(-55);
            } else{
                
                make.centerY.equalTo(self.windowShadowView).offset(-25);
            }
        }];
        [self rotate360DegreeWithImageView:changeLogoImage];
        
        UILabel *showTextLabel = [UILabel setBaseLab:showText fontSize:16 titleColor:COLOR_FONT_LIGHT_GREEN Alignment:NSTextAlignmentCenter];
        [self.windowShadowView addSubview:showTextLabel];
        
        [showTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(changeLogoImage.mas_bottom).offset(30);
            make.centerX.equalTo(self.windowShadowView);
        }];
    }
    return self;
}

- (UIImageView *)rotate360DegreeWithImageView:(UIImageView *)imageView{
    
    CABasicAnimation *animation =  [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    //默认是顺时针效果，若将fromValue和toValue的值互换，则为逆时针效果
    animation.fromValue = [NSNumber numberWithFloat:0.f];
    animation.toValue =  [NSNumber numberWithFloat: M_PI];
    animation.duration  = 0.5;
    animation.autoreverses = NO;
    animation.fillMode =kCAFillModeForwards;
    animation.repeatCount = 500;
    
    [imageView.layer addAnimation:animation forKey:nil];
    return imageView;
}


@end
